﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;

namespace BlackStar
{

    public class ButtonContentReader : ContentTypeReader<Button>
    {
        protected override Button Read(ContentReader input, Button existingInstance)
        {
            Button result = new Button();
            result.ReadContent(input);
            return result;
        }
    }

    public class Button : Component
    {
        public event ComponentEvent Click;

        protected string myStyle = "Default";

        protected internal override void ReadContent(ContentReader input)
        {
            base.ReadContent(input);
        }

        public override void Resize()
        {
            if (layoutSuspended) return;
            base.Resize();
            UpdateSkinRects(gui.theme.Button);
        }

        public override void Draw()
        {
            if (!myVisible) return;

            if (this.HasFocus())
            {
                // draw the focus rectangle.
                gui.theme.Button.Draw("Focused", skinRects, this.Color);
            }
            else
            {
                gui.theme.Button.Draw(myStyle, skinRects, this.Color);
            }

            myGui.theme.Fonts.Draw(myFont, myText, myInterior, this.FontColor);

            // we call this last because child components should be drawn on top of this.
            DrawComponents();
        }

        public override void DoMouseDown(MouseEventArgs e)
        {
            //base.DoMouseDown(e);
            myStyle = "Pressed";
        }

        public override void DoMouseUp(MouseEventArgs e)
        {
            //base.DoMouseUp(e);
            myStyle = "Default";
        }

        public override void DoMouseExit(MouseEventArgs e)
        {
            //base.DoMouseExit(e);
            myStyle = "Default";
        }

        public override void DoMouseClick(MouseEventArgs e)
        {
            OnClick();
        }

        protected void OnClick()
        {
            if (this.Click != null) Click(this);
        }
    }
}
